package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.vo.BizServiceOrderEvaluationFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizServiceOrderEvaluationQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizServiceOrderEvaluationVO;
import cn.sfrog.project.biz.admin.service.IBizServiceOrderEvaluationService;
import cn.sfrog.system.domain.vo.BizAuditVO;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "管理后台-订单评价相关")
@RestController
@RequestMapping("/biz/evaluation")
public class BizServiceOrderEvaluationController extends BaseController {
    @Resource
    private IBizServiceOrderEvaluationService bizServiceOrderEvaluationService;

    /**
     * 查询订单评价列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:evaluation:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizServiceOrderEvaluationQueryVO queryVO) {
        startPage();
        List<BizServiceOrderEvaluationVO> list = bizServiceOrderEvaluationService.selectBizServiceOrderEvaluationList(queryVO);
        return getDataTable(list);
    }

    /**
     * 导出订单评价列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:evaluation:export')")
    @Log(title = "订单评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizServiceOrderEvaluationQueryVO query) {
        List<BizServiceOrderEvaluationVO> list = bizServiceOrderEvaluationService.selectBizServiceOrderEvaluationList(query);
        ExcelUtil<BizServiceOrderEvaluationVO> util = new ExcelUtil<BizServiceOrderEvaluationVO>(BizServiceOrderEvaluationVO.class);
        util.exportExcel(response, list, "订单评价数据");
    }

    /**
     * 获取订单评价详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:evaluation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizServiceOrderEvaluationService.selectBizServiceOrderEvaluationById(id));
    }

    /**
     * 新增订单评价
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:evaluation:add')")
    @Log(title = "订单评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizServiceOrderEvaluationFormVO form) {
        return toAjax(bizServiceOrderEvaluationService.insertBizServiceOrderEvaluation(form));
    }

    /**
     * 修改订单评价
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:evaluation:edit')")
    @Log(title = "订单评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizServiceOrderEvaluationFormVO form) {
        return toAjax(bizServiceOrderEvaluationService.updateBizServiceOrderEvaluation(form));
    }

    /**
     * 删除订单评价
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:evaluation:remove')")
    @Log(title = "订单评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizServiceOrderEvaluationService.deleteBizServiceOrderEvaluationByIds(ids));
    }

    /**
     * 更改状态订单评价
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasPermi('biz:evaluation:changeStatus')")
    @Log(title = "订单评价", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizServiceOrderEvaluationService.changeStatus(vo));
    }

    /**
     * 审核
     * @param auditVO
     * @return
     */
    @ApiOperation("审核")
    @PreAuthorize("@ss.hasPermi('biz:evaluation:audit')")
    @Log(title = "订单评价", businessType = BusinessType.UPDATE)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody @Validated BizAuditVO auditVO){
        return AjaxResult.success(bizServiceOrderEvaluationService.audit(auditVO));
    }
}
